package cn.mesmile.lock.controller;

import cn.mesmile.lock.service.RangeService;
import lombok.AllArgsConstructor;
import org.springframework.data.redis.core.ZSetOperations;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;

/**
 * @author zb
 * @date 2020/12/4 14:32
 * @Description
 */
@AllArgsConstructor
@RequestMapping("/api/v1/range")
@RestController
public class RangeController {

    private final RangeService rangeService;

    @GetMapping("/add/{uid}/{score}")
    public String add(@PathVariable("uid")String uid, @PathVariable("score")Double score){
        boolean b = rangeService.addScore(uid, score);
        return "success";
    }

    @GetMapping("/zIncrby/{uid}/{score}")
    public double zIncrby(@PathVariable("uid")String uid,@PathVariable("score")Double score){
        double v = rangeService.zIncrby(uid, score);
        return v;
    }


    @GetMapping("/get")
    public Object get() {
        Set<ZSetOperations.TypedTuple<Object>> rank = rangeService.getRankKeyValue();
        return rank;
    }

    @GetMapping("/getRank/{uid}")
    public long getRank(@PathVariable("uid") String uid){
        return rangeService.getRank(uid);
    }

    @GetMapping("/getReverseRank/{uid}")
    public long getReverseRank(@PathVariable("uid") String uid){
        return rangeService.getReverseRank(uid);
    }



}
